package web.backend;


import com.easybuy.entity.UserAddress;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class backendServlet extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		if(request.getParameter("type").equals("isDefault")){
//			String type=(String) request.getParameter("type");
			Integer index=new Integer(request.getParameter("status"));
			List<UserAddress> addresses= (List<UserAddress>) request.getSession().getAttribute("addresses");
			UserAddress address=addresses.get(index);
			if(address.getIsDefault()==0){
				out.println("<script>alert('设置默认地址成功！');</script>");
			}else{
				out.println("<script>alert('该地址已经是默认地址，无需再次设置！');</script>");
			}
			response.sendRedirect("/EasyBuy/backend/Member_Address.jsp");
		}
		
		
		out.flush();
		out.close();
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doGet(request, response);
	}

}
